package hospital;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChatClient {
    public static void main(String[] args) {
        //Client
        try {
            Socket socket=new Socket("localhost",8888);
            System.out.println("连接信息:"+socket);
            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            PrintWriter pw=new PrintWriter(out,true);
            Scanner input=new Scanner(System.in);
            while (true){
                System.out.println("开始聊天:");
                String words=input.next();
                pw.println(words);
                String reply=br.readLine();
                System.out.println("服务器回复："+reply);
                if("exit".equals(words))
                    break;
            }
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
